package cc.koit.blog.service.impl;

import cc.koit.blog.dao.entity.Article;
import cc.koit.blog.dao.entity.ArticleType;
import cc.koit.blog.dao.mapper.ArticleMapper;
import cc.koit.blog.dao.mapper.ArticleTypeMapper;
import cc.koit.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gujing
 * @date 2022/2/4 3:04 下午
 * @descrption
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleTypeMapper articleTypeMapper;

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<ArticleType> listTypes() {
        return articleTypeMapper.listAll();
    }

    @Override
    public Long create(String title, String typeId, String summary, String content, String tags) {
        Article article = new Article();
        article.setTitle(title);
        article.setTypeId(typeId);
        article.setSummary(summary);
        article.setContent(content);
        article.setTags(tags);
        articleMapper.insert(article);
        return article.getId();
    }

    @Override
    public Article getById(Long id) {
        return articleMapper.queryById(id);
    }

    @Override
    public void modify(Article article) {
        articleMapper.modify(article);
    }

}
